using System.Web;
using Castle.Core.Resource;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;

namespace OrderSystem.Web.Monorail
{
    public class GlobalApplication : HttpApplication, IContainerAccessor
    {
        public void Application_OnStart()
        {
            if (Container == null)
            {
                Container = new WindsorContainer(new XmlInterpreter(new ConfigResource()));
            }
        }

        public void Application_OnEnd() 
        {
            if (Container != null)
            {
                Container.Dispose();
            }
        }

        public IWindsorContainer Container { get; private set; }
    }
}